package com.totoro.rabbitmq.client;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * Created by Niki on 2018/4/11 14:59
 */
@Configuration
public class ClientBind {
//    @Bean
//    public DirectExchange directExchange(){
//        return new DirectExchange(MQConfig.EXCHANGE_DIRECT_AMQ) ;
//    }
//
//    @Bean(name = "queue_hello")
//    public Queue queueHello(){
//        return new Queue(MQConfig.QUEUE_HELLO, true, false, false);
//    }
//   //将queue绑定到对应的Exchange
//    @Bean
//    public Binding exchange_direct_hello(DirectExchange directExchange, @Qualifier("queue_hello") Queue queue){
//        return BindingBuilder.bind(queue).to(directExchange).with(MQConfig.ROUTINGKEY_HELLO) ;
//    }
//
//    @Bean(name = "bind_hello_2")
//    public Binding exchange_direct_hello_2(DirectExchange directExchange, @Qualifier("queue_hello") Queue queue){
//        return BindingBuilder.bind(queue).to(directExchange).with("exchange_direct_hello_2");
//    }

    @Bean
    public Queue patchQueue() {
        return new Queue("EAS:PATCH:SERVICE:QUEUEA");
    }
    @Bean
    public FanoutExchange patchExchange() {
        return new FanoutExchange("EAS:PATCH:SERVICE:EXCHANGE");
    }
    @Bean
    public Binding patchBinding(Queue patchQueue, FanoutExchange patchExchange) {
        binding(patchExchange);
        return BindingBuilder.bind(patchQueue).to(patchExchange);
    }


    public void binding(FanoutExchange patchExchange) {
        for (int i = 0; i < 100000; i++) {
            Queue queue = new Queue("test_binding_" + i, true, false, true);
            BindingBuilder.bind(queue).to(patchExchange);
        }
    }

}
